<?php
	// On prolonge la session
	session_start();
	$id_anim='';
	$code='';
	
	require_once dirname(__FILE__) . "/../../includes/config.php";
	require_once PHP_ROOTPATH.'/classes/database.php';
	

		// On teste si la variable de session existe et contient une valeur
		if(empty($_SESSION['id_anim'])){
			// Si inexistante ou nulle, on redirige vers la page de saisie du code
			header('Location: ../recherche.php');
			exit();
		}
		else{
			$id_anim=$_SESSION['id_anim'];
			$code=$_SESSION['code'];
		}
	
?>

<!DOCTYPE html>
<html>
	<head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="../../style.css" />
		<!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <!--[if lte IE 7]>
        <link rel="stylesheet" href="../../style_ie.css" />
        <![endif]-->
        <title>Base de données microcèbes</title>
        
		<script type="text/javascript">
			function afficher(oSelect){
				var id=oSelect.id;
				var elt = document.getElementById(id);
				if(elt.style.display=="block"){
					elt.style.display="none";
				}
				else{
					elt.style.display="block";
				}
			}
		</script>
    </head>
    
    <body>
		<?php include((dirname(dirname(dirname(__FILE__))))."/menu.php"); ?>
		
		<section id="main">
			<header>
				<h1>Recherche - Immunologie animal <?php echo $code;?></h1>
			</header>
			<?php include((dirname(dirname(__FILE__)))."/menu_recherche.php"); ?>
			<section id="animal">
				<section id="contenu">
					<?php                 
						$idconnect=Database::getInstance();
						$query=pg_query($idconnect,"SELECT test_immunologique.id_res,date_test,experimentateur,code_anticorps,diagnostic
						FROM test_immunologique,resultat_test,test,type_test 
						WHERE label LIKE '%Test immunologique%' AND id_animal='".$id_anim."'
						AND test_immunologique.id_res=resultat_test.id_res
						AND resultat_test.id_test=test.id_test AND test.id_type_test=type_test.id_type_test ORDER BY date_test");
						$int = pg_num_rows($query);
						if($int==0){echo("<p><label>Pas d'informations disponibles</label></p>");}
						else{
							$i=0;
							//informations test_immunologique
							while ($back = pg_fetch_assoc($query)) {
								if($back["code_anticorps"]){echo "<div><label class=\"titre2\">".$back["code_anticorps"]." (".$back["date_test"].")</label><input type=\"button\" onclick=\"afficher(para".$back["id_res"].")\" value=\"Détail\"></div>";}
								echo "<section class='autre' id=\"para".$back["id_res"]."\"><p>";
								if($back["date_test"]){echo "<label><strong>Date du test: </strong>".date("d/m/Y", strtotime($back["date_test"]))."</label><br/>";}
								if($back["experimentateur"]){echo "<label><strong>Expérimentateur: </strong>".$back["experimentateur"]."</label><br/>";}
								if($back["diagnostic"]){echo "<label><strong>Diagnostic: </strong>".$back["diagnostic"]."</label><br/>";}
								
								//informations lame_immuno
								$query2=pg_query($idconnect,"SELECT * from lame_immuno where lame_immuno.id_res=".$back["id_res"]);
								$int2 = pg_num_rows($query2);
								if($int2==0){echo "<p><label>Pas d'informations disponibles</label></p>";}
								else{
									while ($back2 = pg_fetch_assoc($query2)) {
										if($back2["num_lame"]){echo "<label class=\"titre2\">Lame ".$back2["num_lame"]."</label><input type=\"button\" onclick=\"afficher(lame".$back2["num_lame"]."_$i)\" value=\"Détail\"><br/>";}
										echo "<span class='autre2' id=\"lame".$back2["num_lame"]."_$i\">";	
										if($back2["observation"]){echo "<label><strong>Observation: </strong>".$back2["observation"]."</label><br/>";}
										else{ echo "<label>Pas d'informations sur la lame</label><br/>";}
										
										//informations photo_immuno
										$query3 = pg_query($idconnect,"SELECT * from photo_immuno where photo_immuno.id_res=".$back2["id_res"]. "AND photo_immuno.num_lame=".$back2["num_lame"]);
										$int3 = pg_num_rows($query3);
										if($int3==0){echo("<label>Pas de photographies</label>");}
										else{
											while ($back3 = pg_fetch_assoc($query3)) {
												if($back3["photo"]){
													$date=date("d.m.Y", strtotime($back["date_test"]));
													echo "<img src=\"../../photos_immuno/$date/$id_anim/".$back3['photo']."\"  height=\"40%\" width=\"40%\" 
													alt=\"image ".$back3['photo']." introuvable\"/><br/>";
												}
											}
										}
										echo "</span>";
									}
								}
								echo "<br/></p></section>";
								$i++;
							}
						}
					?>
				</section>
			</section>
		</section>
	</body>
</html>
